package me.keiwu.log.controller.pub;

import com.alibaba.fastjson.JSONObject;
import me.keiwu.log.service.LogDonateService;
import me.keiwu.pub.data.ResponseV2;
import me.keiwu.pub.util.CacheUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


/**
 * Created by kei on 19/12/2017.
 */
@RestController
@RequestMapping("/pub/log/donate")
public class LogDonatePubController {

    private Logger logger = LoggerFactory.getLogger(LogDonatePubController.class);


    @Autowired
    private LogDonateService logDonateService;
    @Autowired
    private CacheUtil cacheUtil;

//    @RequestMapping("/topN")
//    public ResponseV2 getTopN(Integer n) {
//        logger.info("getTopN n={}", n);
//        JSONObject json = new JSONObject();
//        List<LogDonateStep> topN = logDonateService.getTopNLog(n);
//        json.put("topN", topN);
//        json.put("totalSteps", cacheUtil.getTotalDonateSteps());
//        json.put("totalUsers", cacheUtil.getTotalDonateUsers());
//        return ResponseV2.ok(json);
//    }


    @RequestMapping("/data")
    public ResponseV2 getDonateData() {
        logger.info("getDonateData");
        JSONObject json = new JSONObject();
        json.put("totalSteps", cacheUtil.getTotalDonateSteps());
        json.put("totalUsers", cacheUtil.getTotalDonateUsers());
        return ResponseV2.ok(json);
    }

}
